package test05;

public class Test42 {
    public static void main(String[] args) {
        Shape shapes[]={new Circle(),new Rect(),new Square()};
        Circle circle=(Circle)shapes[0];
        Rect rect=(Rect)shapes[1];
        Square square=(Square)shapes[2];

        circle.setR(5);;
        System.out.println(circle.area());
        System.out.println(circle.girth());

        rect.setLength(5);
        rect.setWidth(4);
        System.out.println(rect.area());
        System.out.println(rect.girth());

        square.setSide(10);
        System.out.println(square.area());
        System.out.println(square.girth());
    }
}
class Shape{
    public double area(){
        return 0;
    }
    public double girth(){
        return 0;
    }
}
class Circle extends Shape{
    private double r;

    public double getR() {
        return r;
    }

    public void setR(double r) {
        this.r = r;
    }

    @Override
    public double area() {
        return r*r*Math.PI;
    }

    @Override
    public double girth() {
        return 2*r*Math.PI;
    }
}
class Rect extends Shape{
    private double length;
    private double width;

    public double getLength() {
        return length;
    }

    public void setLength(double length) {
        this.length = length;
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        this.width = width;
    }

    @Override
    public double area() {
        return length*width;
    }

    @Override
    public double girth() {
        return 2*(length+width);
    }
}
class Square extends Rect{
    private double side;

    public double getSide() {
        return side;
    }

    public void setSide(double side) {
        this.side = side;
    }

    @Override
    public double area() {
        return side*side;
    }

    @Override
    public double girth() {
        return 4*side;
    }
}
